package com.doupi.partner.service.impl;

import com.doupi.partner.dal.AdministratorRoleHasPermissionMapper;
import com.doupi.partner.dal.model.AdministratorRoleHasPermission;
import com.doupi.partner.service.AdministratorRoleHasPermissionService;
import com.doupi.partner.util.Pagination;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdministratorRoleHasPermissionServiceImpl implements AdministratorRoleHasPermissionService {
	private final AdministratorRoleHasPermissionMapper administratorRoleToAdministratorPermissionMapper;

	@Autowired
	public AdministratorRoleHasPermissionServiceImpl(AdministratorRoleHasPermissionMapper administratorRoleToAdministratorPermissionMapper) {
		this.administratorRoleToAdministratorPermissionMapper = administratorRoleToAdministratorPermissionMapper;
	}

	public int deleteByPrimaryKey(Long id) {
		return administratorRoleToAdministratorPermissionMapper.deleteByPrimaryKey(id);
	}

	public int insert(AdministratorRoleHasPermission record) {
		return administratorRoleToAdministratorPermissionMapper.insert(record);
	}

	public AdministratorRoleHasPermission selectByPrimaryKey(Long id) {
		return administratorRoleToAdministratorPermissionMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(AdministratorRoleHasPermission record) {
		return administratorRoleToAdministratorPermissionMapper.updateByPrimaryKeySelective(record);
	}

	public int countAdministratorRoleHasPermission(AdministratorRoleHasPermission administratorRoleToAdministratorPermission) {
		return administratorRoleToAdministratorPermissionMapper.countAdministratorRoleHasPermission(administratorRoleToAdministratorPermission);
	}

	public List<AdministratorRoleHasPermission> queryAdministratorRoleHasPermissions(AdministratorRoleHasPermission administratorRoleToAdministratorPermission, RowBounds rowBounds) {
		return administratorRoleToAdministratorPermissionMapper.queryAdministratorRoleHasPermissions(administratorRoleToAdministratorPermission, rowBounds);
	}

	public AdministratorRoleHasPermission selectAdministratorRoleHasPermissionForUpdateByPrimaryKey(Long id) {
		return administratorRoleToAdministratorPermissionMapper.selectAdministratorRoleHasPermissionForUpdateByPrimaryKey(id);
	}

	public Pagination<AdministratorRoleHasPermission, AdministratorRoleHasPermission> queryAdministratorRoleHasPermissions(
			Pagination<AdministratorRoleHasPermission, AdministratorRoleHasPermission> pagination) {
		int count = countAdministratorRoleHasPermission(pagination.getParam());
		pagination.setTotalCount(count);
		if (count > 0) {
			pagination.setRecords(queryAdministratorRoleHasPermissions(pagination.getParam(), new RowBounds(pagination.getOffset(), pagination.getLimit())));
		}
		return pagination;
	}

	@Override
	public int deleteByAdministratorRoleId(Long administratorRoleId) {
		List<AdministratorRoleHasPermission> lists = queryByAdministratorRoleId(administratorRoleId);
		for (AdministratorRoleHasPermission temp : lists) {
			deleteByPrimaryKey(temp.getId());
		}
		return 1;
	}

	@Override
	public int deleteByAdministratorPermissionId(Long administratorPermissionId) {
		AdministratorRoleHasPermission administratorRoleToAdministratorPermission = new AdministratorRoleHasPermission();
		administratorRoleToAdministratorPermission.setAdministratorPermissionId(administratorPermissionId);
		List<AdministratorRoleHasPermission> lists = queryAdministratorRoleHasPermissions(administratorRoleToAdministratorPermission, new RowBounds(0, Integer.MAX_VALUE));
		for (AdministratorRoleHasPermission temp : lists) {
			deleteByPrimaryKey(temp.getId());
		}
		return 1;
	}

	@Override
	public List<AdministratorRoleHasPermission> queryByAdministratorRoleId(Long administratorRoleId) {
		AdministratorRoleHasPermission arAp = new AdministratorRoleHasPermission();
		arAp.setAdministratorRoleId(administratorRoleId);
		return queryAdministratorRoleHasPermissions(arAp, new RowBounds(0, Integer.MAX_VALUE));
	}

}
